package com.msw.design.proxy.cglib;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * Created by minshiwu on 2017/6/4.
 */
public class Hacker implements MethodInterceptor {

    /**
     * 方法级别的代理模式
     *
     *
     * @param o
     * @param method
     * @param args
     * @param methodProxy
     * @return
     * @throws Throwable
     */
    @Override
    public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) throws Throwable {
        preHandler();
        methodProxy.invokeSuper(o, args);
        postHandler();
        return null;
    }


    public void preHandler() {
        System.out.println("before invoke method ...................");
    }

    public void postHandler() {
        System.out.println("after invoke method ....................");
    }

}
